#include "TripLaser.h"
#include "../SGD Wrappers/SGD_Event.h"

TripLaser::TripLaser() : Listener(this)
{
	RegisterForEvent("STUNNED");
	RegisterForEvent("DISABLED");

}


TripLaser::~TripLaser()
{
	UnregisterFromEvent("STUNNED");
	UnregisterFromEvent(ShutDownEvent.c_str());
}


/*virtual*/ void TripLaser::Update(float dt)	 /*override*/
{
	if (isActive)
	{
		if (m_tStunTimer.Update(dt))
		{
			if (animation.m_strCurrAnimation != "tripLaserOn")
			{
				animation.m_fCurrDuration = 0.0f;
				animation.m_nCurrFrame = 0;
				animation.m_strCurrAnimation = "tripLaserOn";
			}

		}
	}

	
}

/*virtual*/ void TripLaser::HandleEvent(const SGD::Event* pEvent) /*override*/
{
	if (pEvent->GetEventID() == "STUNNED")
	{
		m_tStunTimer.AddTime(10);
		animation.m_fCurrDuration = 0.0f;
		animation.m_nCurrFrame = 0;
		animation.m_strCurrAnimation = "tripLaserOff";
	}

	else if (pEvent->GetEventID() == ShutDownEvent.c_str())
	{
		//TODO: Handle computer shutdown event
		animation.m_fCurrDuration = 0.0f;
		animation.m_nCurrFrame = 0;
		animation.m_strCurrAnimation = "tripLaserOff";
		isActive = false;
	}
	

}
/*virtual*/ void TripLaser::HandleCollision(const IBase* pOther) /*override*/
{
	
		if (pOther->GetType() == OBJ_PLAYER)
		{
			if (isActive)
			{
				SGD::Event* alertEvent = new SGD::Event("ALARM_TRIGGERED");
				alertEvent->QueueEvent();
				alertEvent = nullptr;
			}
		}
	}
	
